﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Modulos/Administrador/VistaControl/MasterPageAdministrador.master" AutoEventWireup="true" CodeFile="AdminUsuarios.aspx.cs" Inherits="Modulos_Administrador_VistaControl_Default" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <h2>Administración de Usuarios</h2><br />
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="USR_RUT" 
    DataSourceID="SqlDataSource1">
        <EditItemTemplate>
            USR_RUT:
            <asp:Label ID="USR_RUTLabel1" runat="server" Text='<%# Eval("USR_RUT") %>' />
            <br />
            NOM_USR:
            <asp:TextBox ID="NOM_USRTextBox" runat="server" Text='<%# Bind("NOM_USR") %>' />
            <br />
            AP_PAT_USR:
            <asp:TextBox ID="AP_PAT_USRTextBox" runat="server" 
                Text='<%# Bind("AP_PAT_USR") %>' />
            <br />
            AP_MAT_USR:
            <asp:TextBox ID="AP_MAT_USRTextBox" runat="server" 
                Text='<%# Bind("AP_MAT_USR") %>' />
            <br />
            FONO_USR:
            <asp:TextBox ID="FONO_USRTextBox" runat="server" 
                Text='<%# Bind("FONO_USR") %>' />
            <br />
            MAIL_USR:
            <asp:TextBox ID="MAIL_USRTextBox" runat="server" 
                Text='<%# Bind("MAIL_USR") %>' />
            <br />
            PASS_USR:
            <asp:TextBox ID="PASS_USRTextBox" runat="server" 
                Text='<%# Bind("PASS_USR") %>' />
            <br />
            TIPO_USR:
            <asp:TextBox ID="TIPO_USRTextBox" runat="server" 
                Text='<%# Bind("TIPO_USR") %>' />
            <br />
            ESTADO_USR:
            <asp:CheckBox ID="ESTADO_USRCheckBox" runat="server" 
                Checked='<%# Bind("ESTADO_USR") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Actualizar" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
        </EditItemTemplate>
        <InsertItemTemplate>
            
            <br />
            Crear nuevo usuario:<table style="width: 113%">
                <tr>
                    <td style="width: 110px">
                        RUT:</td>
                    <td>
                        <asp:TextBox ID="USR_RUTTextBox" runat="server" Text='<%# Bind("USR_RUT") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                            ControlToValidate="USR_RUTTextBox" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td style="width: 110px">
                        Nombres:</td>
                    <td>
                        <asp:TextBox ID="NOM_USRTextBox" runat="server" Text='<%# Bind("NOM_USR") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                            ControlToValidate="NOM_USRTextBox" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td style="width: 110px">
                        Apellido paterno:</td>
                    <td>
                        <asp:TextBox ID="AP_PAT_USRTextBox" runat="server" 
                            Text='<%# Bind("AP_PAT_USR") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                            ControlToValidate="AP_PAT_USRTextBox" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td style="width: 110px">
                        Apellido materno:</td>
                    <td>
                        <asp:TextBox ID="AP_MAT_USRTextBox" runat="server" 
                            Text='<%# Bind("AP_MAT_USR") %>' />
                    </td>
                </tr>
                <tr>
                    <td style="width: 110px">
                        Teléfono:</td>
                    <td>
                        <asp:TextBox ID="FONO_USRTextBox" runat="server" 
                            Text='<%# Bind("FONO_USR") %>' />
                    </td>
                </tr>
                <tr>
                    <td style="width: 110px">
                        Mail:</td>
                    <td>
                        <asp:TextBox ID="MAIL_USRTextBox" runat="server" 
                            Text='<%# Bind("MAIL_USR") %>' />
                    </td>
                </tr>
                <tr>
                    <td style="width: 110px">
                        Contraseña:</td>
                    <td>
                        <asp:TextBox ID="PASS_USRTextBox" runat="server" 
                            Text='<%# Bind("PASS_USR") %>' />
                    </td>
                </tr>
                <tr>
                    <td style="width: 110px">
                        Tipo:</td>
                    <td>
                        <asp:TextBox ID="TIPO_USRTextBox" runat="server" 
                            Text='<%# Bind("TIPO_USR") %>' />
                    </td>
                </tr>
                <tr>
                    <td style="width: 110px">
                        Estado:</td>
                    <td>
                        <asp:CheckBox ID="ESTADO_USRCheckBox" runat="server" 
                            Checked='<%# Bind("ESTADO_USR") %>' />
                    </td>
                </tr>
                <tr>
                    <td style="width: 110px">
                        &nbsp;</td>
                    <td>
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                            CommandName="Insert" Text="Insertar" />
                        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
                    </td>
                </tr>
            </table>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Crear nuevo usuario" />
        </ItemTemplate>
        <EmptyDataTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Crear nuevo usuario" />
        </EmptyDataTemplate>
    </asp:FormView>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="USR_RUT"
        DataSourceID="SqlDataSource1" 
    EmptyDataText="No hay registros de datos para mostrar." AllowPaging="True" 
    AllowSorting="True">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="USR_RUT" HeaderText="RUT" ReadOnly="True" SortExpression="USR_RUT" />
            <asp:BoundField DataField="NOM_USR" HeaderText="Nombres" SortExpression="NOM_USR" />
            <asp:BoundField DataField="AP_PAT_USR" HeaderText="Ap. Paterno" SortExpression="AP_PAT_USR" />
            <asp:BoundField DataField="AP_MAT_USR" HeaderText="Ap. Materno" SortExpression="AP_MAT_USR" />
            <asp:BoundField DataField="FONO_USR" HeaderText="Teléfono" SortExpression="FONO_USR" />
            <asp:BoundField DataField="MAIL_USR" HeaderText="Mail" SortExpression="MAIL_USR" />
            <asp:BoundField DataField="PASS_USR" HeaderText="Contraseña" SortExpression="PASS_USR" />
            <asp:BoundField DataField="TIPO_USR" HeaderText="Tipo" SortExpression="TIPO_USR" />
            <asp:CheckBoxField DataField="ESTADO_USR" HeaderText="Estado" SortExpression="ESTADO_USR" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>"
        DeleteCommand="DELETE FROM [USUARIO] WHERE [USR_RUT] = @USR_RUT" InsertCommand="INSERT INTO [USUARIO] ([USR_RUT], [NOM_USR], [AP_PAT_USR], [AP_MAT_USR], [FONO_USR], [MAIL_USR], [PASS_USR], [TIPO_USR], [ESTADO_USR]) VALUES (@USR_RUT, @NOM_USR, @AP_PAT_USR, @AP_MAT_USR, @FONO_USR, @MAIL_USR, @PASS_USR, @TIPO_USR, @ESTADO_USR)"
        ProviderName="<%$ ConnectionStrings:AppCeiiConnectionString.ProviderName %>"
        SelectCommand="SELECT [USR_RUT], [NOM_USR], [AP_PAT_USR], [AP_MAT_USR], [FONO_USR], [MAIL_USR], [PASS_USR], [TIPO_USR], [ESTADO_USR] FROM [USUARIO]"
        UpdateCommand="UPDATE [USUARIO] SET [NOM_USR] = @NOM_USR, [AP_PAT_USR] = @AP_PAT_USR, [AP_MAT_USR] = @AP_MAT_USR, [FONO_USR] = @FONO_USR, [MAIL_USR] = @MAIL_USR, [PASS_USR] = @PASS_USR, [TIPO_USR] = @TIPO_USR, [ESTADO_USR] = @ESTADO_USR WHERE [USR_RUT] = @USR_RUT">
        <DeleteParameters>
            <asp:Parameter Name="USR_RUT" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="USR_RUT" Type="Int32" />
            <asp:Parameter Name="NOM_USR" Type="String" />
            <asp:Parameter Name="AP_PAT_USR" Type="String" />
            <asp:Parameter Name="AP_MAT_USR" Type="String" />
            <asp:Parameter Name="FONO_USR" Type="String" />
            <asp:Parameter Name="MAIL_USR" Type="String" />
            <asp:Parameter Name="PASS_USR" Type="String" />
            <asp:Parameter Name="TIPO_USR" Type="String" />
            <asp:Parameter Name="ESTADO_USR" Type="Boolean" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="NOM_USR" Type="String" />
            <asp:Parameter Name="AP_PAT_USR" Type="String" />
            <asp:Parameter Name="AP_MAT_USR" Type="String" />
            <asp:Parameter Name="FONO_USR" Type="String" />
            <asp:Parameter Name="MAIL_USR" Type="String" />
            <asp:Parameter Name="PASS_USR" Type="String" />
            <asp:Parameter Name="TIPO_USR" Type="String" />
            <asp:Parameter Name="ESTADO_USR" Type="Boolean" />
            <asp:Parameter Name="USR_RUT" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>

